new Vue({
    el: '#app',
    data: {
        loading: false,
        tableData: [],//用户列表数据源
        queryData: {//用户查询数据源
            name:'', //姓名
            status:''//状态
        },
        count: 0,//查询总共条数
        dialogVisible:false,//修改弹窗 显示/隐藏
        detailInfo:null,//用户详情
        statusList:[],//用户状态
        addForm:{//修改用户数据源
            id:'',
            name: '',
            username: '',
            status:'',
        },


    },
    created() {
        this.getList();//获取用户列表接口
        this.getStatusList();//获取用户状态接口

    },
    methods: {
        //修改用户信息
        onUpdate(row){
            this.dialogVisible = true
            this.addForm.id = row.id
            this.addForm.name = row.name
            this.addForm.username = row.username
            this.addForm.status = row.status

        },
        //分页pageNum监听
        handleCurrentChange(val) {
            this.queryData.page = val
            this.getList()
        },
        //分页pageSize监听
        handleSizeChange(val) {
            this.queryData.page = 1
            this.queryData.limit = val
            this.getList()
        },
        //获取用户列表接口
        getList() {
            this.loading = true
            $.ajax({
                type: 'post',
                url: '/authUser/list',
                data: this.queryData,
                dataType: 'json',
                success: (res, s, xhr) => {
                    if (res.code == 0) {
                        this.tableData = res.data.items
                        this.count = res.data.itemsTotalCount

                    } else {
                        this.$message.error(res.msg || '网络异常')
                    }
                    this.loading = false
                },
                error: (xhr, s, err) => {
                    console.log(xhr, s, err)
                    this.$message.error(err.msg || '网络异常')
                    this.loading = false
                    return false;
                }
            });
        },
        //获取用户状态接口
        getStatusList() {
            this.loading = true
            $.ajax({
                type: 'post',
                url: '/authUser/statusList',
                data: {},
                dataType: 'json',
                success: (res, s, xhr) => {
                    if (res.code == 0) {
                        this.statusList = res.data
                    } else {
                        this.$message.error(res.msg || '网络异常')
                    }
                    this.loading = false
                },
                error: (xhr, s, err) => {
                    console.log(xhr, s, err)
                    this.$message.error(err.msg || '网络异常')
                    this.loading = false
                    return false;
                }
            });
        },
        //提交用户修改
        submitForm(){
            this.update()
        },
        //修改用户信息接口
        update(id){
            this.loading = true
            $.ajax({
                type: 'post',
                url: '/authUser/update',
                data: this.addForm,
                dataType: 'json',
                success: (res, s, xhr) => {
                    if (res.code == 0) {
                        this.dialogVisible = false
                        this.getList();
                        this.$message.success('修改成功')
                    } else {
                        this.$message.error(res.msg || '网络异常')
                    }
                    this.loading = false
                },
                error: (xhr, s, err) => {
                    console.log(xhr, s, err)
                    this.$message.error(err.msg || '网络异常')
                    this.loading = false
                    return false;
                }
            });
        },
    }
})
